1
2
3
4
5 package io;
6
7 /***
8 * Represents a rethrown exception. Classes can subclass this
9 * to provide a package specific version of an exception but keep
10 * the offending exception as the details. Provides a Facade for other Exception types.
11 *
12 * @author Barrie Treloar
13 */
14 public class RethrownException extends Exception
15 {
16 private Exception rethrownException;
17
18 public RethrownException( Exception e )
19 {
20 rethrownException = e;
21 }
22
23 public RethrownException( String s )
24 {
25 super( s );
26 }
27
28 /***
29 * Returns the error message string of this Exception object.
30 *
31 * @return the error message string of this <code>Exception</code> or
32 * if a rethrown Exception then use that exceptions message.
33 *
34 */
35 public String getMessage()
36 {
37 String result = null;
38 if ( rethrownException != null )
39 {
40 result = rethrownException.getMessage();
41 }
42 else
43 {
44 result = super.getMessage();
45 }
46
47 return result;
48 }
49
50 /***
51 * Print the stack trace for this Exception or the rethrown exception.
52 */
53 public void printStackTrace()
54 {
55 if ( rethrownException != null )
56 {
57 rethrownException.printStackTrace();
58 }
59 else
60 {
61 super.printStackTrace();
62 }
63 }
64
65 /***
66 * Print the stack trace for this Exception or the rethrown exception.
67 */
68 public void printStackTrace(java.io.PrintStream s)
69 {
70 if ( rethrownException != null )
71 {
72 rethrownException.printStackTrace( s );
73 }
74 else
75 {
76 super.printStackTrace( s );
77 }
78 }
79
80 /***
81 * Print the stack trace for this Exception or the rethrown exception.
82 */
83 public void printStackTrace(java.io.PrintWriter s)
84 {
85 if ( rethrownException != null )
86 {
87 rethrownException.printStackTrace( s );
88 }
89 else
90 {
91 super.printStackTrace( s );
92 }
93 }
94
95 public String toString()
96 {
97 String result = null;
98
99 if ( rethrownException != null )
100 {
101 result = rethrownException.toString();
102 }
103 else
104 {
105 result = super.toString();
106 }
107 return result;
108 }
109 }